<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="请假申请"></uni-navbar></view>

		<view class="form-box">
			<u-form :model="form" ref="uForm">
				<u-form-item class="form-item" required label="请假事由" prop="leaveReasion">
					<u-input v-model="form.leaveReasion" type="textarea" placeholder="请输入请假事由" :clearable="false" :height="160" :maxlength="-1" />
				</u-form-item>

				<u-form-item class="form-item" label="上传文件"><uni-file-upload style="width: 500rpx"></uni-file-upload></u-form-item>
			</u-form>
		</view>

		<view class="fiexd-btm"><u-button class="form-btn" type="error" @click="confirm">提交</u-button></view>

		<view v-if="false && id"></view>
	</view>
</template>

<script>
import uniFileUpload from '@/components/uni-file-uploader.vue';
import { mapState } from 'vuex';
export default {
	components: {
		uniFileUpload
	},
	data() {
		return {
			id: '',
			form: {
				leaveReasion: ''
			},
			rules: {
				leaveReasion: [
					{
						required: true,
						message: '请输入请假事由',
						trigger: 'change'
					}
				]
			}
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	onUnload() {
		this.$store.commit('filePush', []);
	},
	computed: {
		...mapState(['userInfo', 'fileList'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
			} else {
				this.$logout();
			}
		},
		confirm() {
			this.$refs.uForm.validate((valid) => {
				if (!valid) {
					return false;
				} else {
					let data = {
						leaveReasion: this.form.leaveReasion,
						fileList: this.fileList
					};

					this.$request('/huiyihuodong/hyhd-meeting-user/attendMeetingState?id=' + this.id + '&state=qingjia&userId=' + this.userId, data, {
						load: true
					}).then((res) => {
						this.$msg('申请成功');
						setTimeout(() => {
							let pre = this.$prePage();
							if (pre && pre.remark4) {
								pre.remark4 = 2;
							}
							uni.navigateBack();
						}, 500);
					});
				}
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
		border-bottom: 20rpx solid $u-border-color;
	}

	.form-checkbox {
		margin: -8rpx 0;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
